package com.oop;

import org.springframework.boot.autoconfigure.SpringBootApplication;

@SpringBootApplication
public class OopApplication {

    public static void main(String[] args) {
        // 类：抽象的，实例化
        // 类实例化以后返回一个具体的结果，返回一个自己的对象
        // student对象就是一个Student类的一个具体实例
        Student xiaoming = new Student();
        Student xiaohong = new Student();
        System.out.println(xiaoming.name);
        System.out.println(xiaoming.sex);
        xiaoming.name = "xiaoming";
        xiaoming.sex = "15";
        System.out.println(xiaoming.name);
        System.out.println(xiaoming.sex);
        System.out.println("=========================================");


        demo07 wo = new demo07("tanswc11");
        // 即使类中无此方法也可以调用，说明默认存在一个方法（构造方法），可以对比class文件发现，class文件相比较java文件，多了一个与类名相同的方法（构造方法）
        System.out.println(wo.name);
        demo07 person1 = new demo07("tanswc12", 23);
        System.out.println("=========================================");


        demo08 dog = new demo08();
        dog.name = "旺财";
        dog.age = 3;
        dog.shout();
        System.out.println(dog.name);
        System.out.println(dog.age);
        demo08 cat = new demo08();
        cat.shout();
        System.out.println(cat.name);
        System.out.println(cat.age);
        System.out.println("=========================================");


        demo09 s1 = new demo09();
        String name = s1.getName();
        s1.setName("tanswc");
        System.out.println(s1.getName());
        s1.setAge(-1);//不合法就输入年龄为3岁，低龄儿童
        System.out.println(s1.getAge());
        System.out.println("=========================================");


        demo11 s2 = new demo11();
        System.out.println("==============================");
        s2.say();
        System.out.println(s2.money);
        System.out.println("==============================");
        s2.test("王羲之");
        System.out.println("==============================");
        s2.test1();
        System.out.println("=========================================");



        //静态方法和非静态的方法区别很大
        //方法的调用之和左边（定义的数据类型）有关
        //非静态方法：重写，且只能是public
        rewriteDemo13 a = new rewriteDemo13();
        a.test();//A
        //父类的引用指向了子类
        rewriteDemo12 b = new rewriteDemo13();
        b.test();//B
        //非静态方法
        a.test1();
        b.test1();//子类重写了父类的方法
        System.out.println("=========================================");



        //一个对象的实际类型是确定的
        //new Student();
        //new Person();
        //可以指向的引用类型就不确定了：父类的引用指向子类的类型
        //Student能调用的方法都是自己的，或者继承父类的
        Student s3 = new Student();
        //Person 父类型，可以指向子类，但是不能调用子类独有的方法
        Person s4 = new Student();
        Object s5 = new Student();
        s4.run();//子类重写了父类的方法，执行子类的方法
        s3.run();
        //对象能执行哪些方法，主要看对象左边的类型，和右边关系不大！
        //s4.eat();
        ((Student) s4).eat();//输入“s4.”自动联想出“ ((Student) s4).eat();”，类型强制转换Person s4 = new Student();
        s3.eat();
        System.out.println("=========================================");



        //Object > String
        //Object > Person > Student
        //Object > Person > Teacher
        //System.out.println(x instanceof y);能不能编译通过？通过表示x和y有父子关系，x指向的类型是y的子类型
        Object object = new Student();
        System.out.println(object instanceof Student);//true
        System.out.println(object instanceof Person);//true
        System.out.println(object instanceof Object);//true
        System.out.println(object instanceof Teacher);//False
        System.out.println(object instanceof String);//False
        System.out.println("=========================================");
        Person person = new Student();
        System.out.println(person instanceof Student);//true
        System.out.println(person instanceof Person);//true
        System.out.println(person instanceof Object);//true
        System.out.println(person instanceof Teacher);//False
        //System.out.println(person instanceof String);//编译报错
        System.out.println("=========================================");
        Student student = new Student();
        System.out.println(student instanceof Student);//true
        System.out.println(student instanceof Person);//true
        System.out.println(student instanceof Object);//true
        //System.out.println(student instanceof Teacher);//False
        //System.out.println(person instanceof String);//编译报错
        System.out.println("=========================================");
        //类型之间的转化：基本类型转换，高转低强转，反之不需要
        //类型之间的转化：父 子
        //高---------------->低
        Person obj = new Student();
        //student1 将这个对象转化为Student类型，我们就可以使用Student类型的方法了
        Student student1= (Student) obj;
        student1.go();
        //以上两步可以写成一步：
        ((Student) obj).go();//
        //低---------------->高
        Person person2 = student1;
        //person2.go();子类转换成父类，可能丢失自己本来的一些方法
        System.out.println("=========================================");



        // abstractDemo16 action = new abstractDemo16(); //无法new出来


    }
}
